package com.ruoyi.framework.security.filter.ykb;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 身份验证过程中使用的令牌
 */
public class YKBAuthenticationToken extends AbstractAuthenticationToken {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private final Object principal;

	private Object credentials;

	public void setCredentials(Object credentials) {
		this.credentials = credentials;
	}

	private String code;

	public YKBAuthenticationToken(String code) {
		super(null);
		this.principal = code;
		this.setCode(code);
	}

	public YKBAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
		super(authorities);
		this.principal = principal;
        this.credentials = credentials;
        super.setAuthenticated(true); // must use super, as we override
	}

	@Override
	public Object getCredentials() {
		return credentials;
	}

	@Override
	public Object getPrincipal() {
		return principal;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Override
	public String toString() {
		return "YKZAuthenticationToken [principal=" + principal + ", credentials=" + credentials + ", code=" + code
				+ "]";
	}

}
